<template>
  <div class="HomeSwiper">
    <form action="/">
      <van-search
        v-model="search"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
      />
    </form>
    <van-swipe :autoplay="3000" class="my-swipe" indicator-color="white">
      <van-swipe-item v-for="item in bannerData" :key="item.id">
        <img :src="item.picUrl" alt="#" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "HomeSwiper",
  components: {},
  data() {
    return {
      search: "",
      bannerData: [],
    };
  },
  created() {
    this.getBanner();
  },

  methods: {
    onSearch(val) {
      console.log(val);
    },
    onCancel() {
      console.log("取消");
    },
    getBanner() {
      var that = this;
      axios
        .get("api/recommend/banner")
        .then(function (response) {
          var data = response.data.data;
          that.bannerData = data;
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
};
</script>

<style scoped>
.my-swipe .van-swipe-item img {
  width: 90%;
  border-radius: 20px;
}
.my-swipe .van-swipe-item {
  text-align: center;
}
</style>